/**
 * @description 路由实例
 */
import Vue from 'vue';
import Router from "vue-router";
import routesLoader from "./router";
import { appRegister } from '../../../config/appServies' 

Vue.use(Router)

const [routerPush, routerReplace] = [Router.prototype.push, Router.prototype.replace];
Router.prototype.push = function push (location) {
    return routerPush.call(this, location).catch(error => error);
};
Router.prototype.replace = function replace (location) {
    return routerReplace.call(this, location).catch(error => error);
};

const routes = routesLoader();

// 为每个路由注册beforeEnter（路由独享的守卫，即加守卫导航）
for (let route of routes) {
    route.path = appRegister.otherApp.hijackUrl + route.path
    // 进入路由之前
    route.beforeEnter = (to, from, next) => {
        document.title = to.meta.title || ""
        next()
    }
}

const router = new Router({
    mode: "hash",
    routes
});

export default router;
